package com.itcoon.cloud.framework.springdoc.plugin;/**
 * @author Athric Yu
 * 2024/11/25
 **/

import com.fasterxml.jackson.databind.type.SimpleType;
import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.oas.models.media.Schema;
import org.springdoc.core.customizers.PropertyCustomizer;

import java.lang.reflect.Type;

/**
 *
 *
 * @author Athric Yu
 * 2024/11/25
 **/
public class LongPropertyCustomizer implements PropertyCustomizer {

    @Override
    public Schema<?> customize(Schema property, AnnotatedType annotatedType) {
        Type type = annotatedType.getType();
        // 检查实例并转换
        if (type instanceof SimpleType) {
            SimpleType fieldType = (SimpleType)type;
            // 获取字段class
            Class<?> fieldClazz = fieldType.getRawClass();
            // 是否是枚举
            if (Long.class.equals(fieldClazz)) {
                property.setExample(1L);
                property.setType(String.class.getSimpleName().toLowerCase());
            }
        }
        return property;
    }
}
